package com.gqqx.user.controller;

import com.gqqx.common.constans.RedisPrefix;
import com.gqqx.common.result.Rt;
import com.gqqx.user.pojo.User;
import com.gqqx.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


@RestController
@RequestMapping("/qx")
@CrossOrigin
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public Rt login(HttpSession session,String name, String password) {
        return userService.userLogin(session,name,password);

    }

    @ApiOperation("用户退出")
    @GetMapping("/logout")
    @RequestMapping("/logout")
    public Rt logout(HttpServletRequest request,Long id){
        //清理session中保存的用户id
        request.getSession().removeAttribute("user");
//        redisTemplate.delete(RedisPrefix.ID_KEY + id);
        return Rt.success();
    }
}
